package com.wc.AlgoOJ_homework.AlgoOJ_BL2.J_最大开支;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.PriorityQueue;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2024/4/1 20:09
 * @description http://43.138.190.70:8888/p/1132?tid=6602a6e518e03a818a4bf047
 */
public class Main {
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int n, m, k, b;
    static PriorityQueue<T> q = new PriorityQueue<>(T::compareTo);

    public static void main(String[] args) {
        n = sc.nextInt();
        m = sc.nextInt();
        for (int i = 1; i <= m; i++) {
            k = sc.nextInt();
            b = sc.nextInt();
            q.add(new T(k, b));
        }
        long res = 0;
        while (n-- > 0 && !q.isEmpty()) {
            T t = q.poll();
            if (t.p > 0) {
                res += t.p;
                t.p = ((long) t.k * (t.n + 1) + t.b) * (t.n + 1) - ((long) t.k * t.n + t.b) * t.n;
                t.n++;
                q.add(t);
            }
        }
        out.println(res);
        out.flush();
    }

    static class T implements Comparable<T> {
        int k;
        // 当前购买差值
        long p;
        int b;
        // 当前购买人数
        int n;

        public T(int k, int b) {
            this.k = k;
            this.b = b;
            n = 1;
            p = Math.max(k * n + b, 0);
        }

        @Override
        public int compareTo(T o) {
            return Long.compare(o.p, this.p);
        }
    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}
